package cn.maidouya.dictionary.service.impl;
import cn.maidouya.basic.util.PageList;
import cn.maidouya.dictionary.domain.DictionaryType;
import cn.maidouya.dictionary.mapper.DictionaryDetailMapper;
import cn.maidouya.dictionary.mapper.DictionaryTypeMapper;
import cn.maidouya.dictionary.mapper.KeyUtilMapper;
import cn.maidouya.dictionary.query.DictionaryTypeQuery;
import cn.maidouya.dictionary.service.IDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DictionaryTypeServiceImpl implements IDictionaryTypeService {
    @Autowired
    private DictionaryTypeMapper dictionaryTypeMapper;
    @Autowired
    private DictionaryDetailMapper dictionaryDetailMapper;

    @Autowired
    private KeyUtilMapper keyUtilMapper;
    @Override
    @Transactional
    public void add(DictionaryType dictionaryType) {
        dictionaryTypeMapper.add(dictionaryType);
    }

    @Override
    @Transactional
    public void del(Long id) {
        keyUtilMapper.closeForienKey();
        dictionaryDetailMapper.batchDel(id);
        dictionaryTypeMapper.del(id);
        keyUtilMapper.openForienKey();
    }

    @Override
    @Transactional
    public void update(DictionaryType dictionaryType) {
        dictionaryTypeMapper.update(dictionaryType);
    }

    @Override
    public DictionaryType finOne(Long id) {
        return dictionaryTypeMapper.finOne(id);
    }

    @Override
    public List<DictionaryType> finAll() {
        return dictionaryTypeMapper.finAll();
    }

    @Override
    public PageList<DictionaryType> findPage(DictionaryTypeQuery dictionaryTypeQuery) {
        Integer total = dictionaryTypeMapper.totalsCount(dictionaryTypeQuery);
        List<DictionaryType> list = dictionaryTypeMapper.findPage(dictionaryTypeQuery);
        PageList<DictionaryType> pageList = new PageList<DictionaryType>(total, list);
        return pageList;
    }
}
